package jdk8.Lambda;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Comparator;

public class LambdaDelay {
    private static void log(int level, String msg) {
        if (level == 1) {
            System.out.println(msg);
        }
    }

//    public static void main(String[] args) {
//        String msgA = "Hello";
//        String msgB = "World";
//        String msgC = "Java";
//        log(1, msgA + msgB + msgC);
//    }

    public static void main(String[] args) {
        String msgA = "Hello";
        String msgB = "World";
        String msgC = "Java";
        log(1, () -> {
            System.out.println("Lambda执行！");
            return msgA + msgB + msgC;
        });
    }

    private static void log(int level, MessageBuilder builder) {
        if (level == 1) {
            System.out.println(builder.buildMessage());
        }
    }
    @FunctionalInterface
    public interface MessageBuilder {
        String buildMessage();
    }

    private static Comparator<String> newComparator() {
        return (a, b) -> b.length() - a.length();
    }

    @Test
    public  void ccc() {
        String[] array = {"abc", "ab", "abcd"};
        System.out.println(Arrays.toString(array));
        Arrays.sort(array, newComparator());
        System.out.println(Arrays.toString(array));
    }
}

